import 'dart:convert';
import 'package:flutter/services.dart';
import '../model/category_model.dart';

class JsonParse{
  static Future<List<CategoryModel>> loadCategoryJson() async{
    //1.加载json文件 属于异步操作
    final jsonString = await rootBundle.loadString('assets/json/category.json');

    //将json字符串转换成Map
    final result = json.decode(jsonString);

    //将Map转换成对象
    final resultlist = result['category'];
    List<CategoryModel> list = [];
    for (var json in resultlist){
       list.add(CategoryModel.fromJson(json));
    }
    return list;
  }
}